﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Framework_Tool
{
    /// <summary>
    /// Interaction logic for AssessmentUpdate.xaml
    /// </summary>
    public partial class AssessmentUpdate : Page
    {
        MainWindow main;

        public AssessmentUpdate()
        {
            InitializeComponent();

            /*asmntIDCmbx_updateAsmnt.SelectionChanged -= asmntIDCmbx_SelectionChanged_1;
            unitNameCmbx_AsmntUpdate.SelectionChanged -= unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            asmntTypeCmbx_Update.SelectionChanged -= asmntTypeCmbx_Update_SelectionChanged_1;
            */

            Database.FindID_AsmntUpdate(this);
            Database.FindUnitTitle_AsmntUpdate(this);

            viewAssessmentBtn.FontWeight = FontWeights.Normal;
            addAssessmentBtn.FontWeight = FontWeights.Normal;
            updateAssessmentBtn.FontWeight = FontWeights.ExtraBold;
            deleteAssessmentBtn.FontWeight = FontWeights.Normal;
            searchAssessmentBtn.FontWeight = FontWeights.Normal;

            /*
            asmntIDCmbx_updateAsmnt.SelectionChanged += asmntIDCmbx_SelectionChanged_1;
            unitNameCmbx_AsmntUpdate.SelectionChanged += unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            asmntTypeCmbx_Update.SelectionChanged += asmntTypeCmbx_Update_SelectionChanged_1;
             */
        }

        private void asmntUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            /* asmntIDCmbx_updateAsmnt.SelectionChanged -= asmntIDCmbx_SelectionChanged_1;
            unitNameCmbx_AsmntUpdate.SelectionChanged -= unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            asmntTypeCmbx_Update.SelectionChanged -= asmntTypeCmbx_Update_SelectionChanged_1; */

            Database.UpdateAsmnt(this);
            
            /*unitNameCmbx_AsmntUpdate.SelectionChanged += unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            asmntTypeCmbx_Update.SelectionChanged += asmntTypeCmbx_Update_SelectionChanged_1;
            asmntIDCmbx_updateAsmnt.SelectionChanged += asmntIDCmbx_SelectionChanged_1; */
        }

        private void unitNameCmbx_AsmntUpdate_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            /* asmntIDCmbx_updateAsmnt.SelectionChanged -= asmntIDCmbx_SelectionChanged_1;
            asmntTypeCmbx_Update.SelectionChanged -= asmntTypeCmbx_Update_SelectionChanged_1;
            unitNameCmbx_AsmntUpdate.SelectionChanged -= unitNameCmbx_AsmntUpdate_SelectionChanged_1; */
            Database.populateUnitID_AsmntUpdate(this);
            /* asmntIDCmbx_updateAsmnt.SelectionChanged += asmntIDCmbx_SelectionChanged_1;
            asmntTypeCmbx_Update.SelectionChanged += asmntTypeCmbx_Update_SelectionChanged_1;
            unitNameCmbx_AsmntUpdate.SelectionChanged += unitNameCmbx_AsmntUpdate_SelectionChanged_1; */
        }

        public void clearAsmntGrid()
        {
            eDetailsGrid_updateAsmnt.Visibility = Visibility.Hidden;
            fitbDetailsGrid_updateAsmnt.Visibility = Visibility.Hidden;
            mcDetailsGrid_updateAsmnt.Visibility = Visibility.Hidden;
            wsDetailGrid_updateAsmnt.Visibility = Visibility.Hidden;
        }

        private void asmntTypeCmbx_Update_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            //asmntIDCmbx_updateAsmnt.SelectionChanged -= asmntIDCmbx_SelectionChanged_1;
            //unitNameCmbx_AsmntUpdate.SelectionChanged -= unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            // string x = asmntTypeCmbx_Update.SelectedValue.ToString();

            if (asmntTypeCmbx_Update.SelectedIndex == 0)
            {
                clearAsmntGrid();
                eDetailsGrid_updateAsmnt.Visibility = Visibility.Visible;
            }

            if (asmntTypeCmbx_Update.SelectedIndex == 1)
            {
                clearAsmntGrid();
                fitbDetailsGrid_updateAsmnt.Visibility = Visibility.Visible;
            }

            if (asmntTypeCmbx_Update.SelectedIndex == 2)
            {
                clearAsmntGrid();
                mcDetailsGrid_updateAsmnt.Visibility = Visibility.Visible;
            }

            if (asmntTypeCmbx_Update.SelectedIndex == 3)
            {
                clearAsmntGrid();
                wsDetailGrid_updateAsmnt.Visibility = Visibility.Visible;
            }

            e.Handled = true;
            // asmntIDCmbx_updateAsmnt.SelectionChanged += asmntIDCmbx_SelectionChanged_1;
            // unitNameCmbx_AsmntUpdate.SelectionChanged += unitNameCmbx_AsmntUpdate_SelectionChanged_1;
        }

        private void cancelAsmntUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            //asmntIDCmbx_updateAsmnt.SelectionChanged -= asmntIDCmbx_SelectionChanged_1;
            //unitNameCmbx_AsmntUpdate.SelectionChanged -= unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            //asmntTypeCmbx_Update.SelectionChanged -= asmntTypeCmbx_Update_SelectionChanged_1;

            asmntIDCmbx_updateAsmnt.Text = "";
            asmntTitleTxt.Text = "";
            unitNameCmbx_AsmntUpdate.Text = "";
            unitIDLbl_AsmntUpdate.Content = "";
            asmntTypeCmbx_Update.Text = "";
            asmntDescTxtB.Text = "";
            clearAsmntGrid();

            //asmntIDCmbx_updateAsmnt.SelectionChanged += asmntIDCmbx_SelectionChanged_1;
            //unitNameCmbx_AsmntUpdate.SelectionChanged += unitNameCmbx_AsmntUpdate_SelectionChanged_1;
            //asmntTypeCmbx_Update.SelectionChanged += asmntTypeCmbx_Update_SelectionChanged_1;
        }

        private void viewAssessmentBtn_Click_1(object sender, RoutedEventArgs e)
        {
            AssessmentView asmntViewWindow = new AssessmentView();
            asmntViewWindow.Content = null;
            mainContent.Children.Add(asmntViewWindow.mainContent);
        }

        private void addAssessmentBtn_Click_1(object sender, RoutedEventArgs e)
        {
            AssessmentAdd asmntAddWindow = new AssessmentAdd();
            asmntAddWindow.Content = null;
            mainContent.Children.Add(asmntAddWindow.mainContent);
        }

        private void deleteAssessmentBtn_Click_1(object sender, RoutedEventArgs e)
        {
            AssessmentDelete asmntDeleteWindow = new AssessmentDelete();
            asmntDeleteWindow.Content = null;
            mainContent.Children.Add(asmntDeleteWindow.mainContent);
        }

        private void searchAssessmentBtn_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void asmntIDCmbx_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Database.populateFields_asmntUpdate(this);
        }

        // *********************************************** ESSAY ***********************************************
 
        // *********************************************** FILL IN THE BLANKS ***********************************************

        // *********************************************** MULTIPLE CHOICE ***********************************************

        private void mcCorrectAddBtn_Click_1(object sender, RoutedEventArgs e)
        {
            mcCorrectAnsListBox.Visibility = Visibility.Visible;
            foreach (String li in mcCorrectAnsListBox.Items)
            {
                if (li.Equals(mcCorrectAnsTxt.Text.ToString()))
                {
                    return;
                }
            }

            mcCorrectAnsListBox.Items.Add(mcCorrectAnsTxt.Text.ToString());
            mcCorrectAnsTxt.Text = null;
        }

        private void mcCorrectDeleteBtn_Click_1(object sender, RoutedEventArgs e)
        {
            Database.DeleteMCCorrectAnsRow_updatedAsmnt(this);
            mcCorrectAnsListBox.Items.Remove(mcCorrectAnsListBox.SelectedItem);

        }

        private void mcAltAddBtn_Click_1(object sender, RoutedEventArgs e)
        {
            foreach (String li in mcAltAnsListBox.Items)
            {

                if (li.Equals(mcAltAnsTxt.Text.ToString()))
                {
                    return;
                }
            }

            mcAltAnsListBox.Items.Add(mcAltAnsTxt.Text.ToString());
            mcAltAnsTxt.Text = null;
        }

        private void mcAltAnsDeleteBtn_Click_1(object sender, RoutedEventArgs e)
        {
            Database.DeleteMCAltAnsRow_updateAsmnt(this);
            mcAltAnsListBox.Items.Remove(mcAltAnsListBox.SelectedItem);
        }

        private void mcQuIDCmbx_updateAsmnt_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            Database.populateMcQus_asmntUpdate(this);
        }

        private void updateMCQu_updateAsmnt_Click_1(object sender, RoutedEventArgs e)
        {

        }

        // *********************************************** WORDSEARCH ***********************************************

        private void wsWordAdd_Click_1(object sender, RoutedEventArgs e)
        {
            foreach (String li in wsWordsListBox.Items)
            {
                if (li.Equals(wsWordTxt_updateAsmnt.Text.ToString()))
                {
                    return;
                }
            }
            wsWordsListBox.Items.Add(wsWordTxt_updateAsmnt.Text.ToString());
            wsWordTxt_updateAsmnt.Text = null;
        }

        private void wsWordDelete_Click_1(object sender, RoutedEventArgs e)
        {
            Database.DeleteWsWordRow_updateAsmnt(this);
            wsWordsListBox.Items.Remove(wsWordsListBox.SelectedItem.ToString());
        }
    }
}
